# Use the official Node.js image as the base image
#FROM node:16-alpine as build-stage
FROM node as build-stage

# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application
COPY . .

# 接受从 docker-compose 传递的 GLOBAL_HOST 参数
ARG GLOBAL_HOST
ENV VITE_GLOBAL_HOST=$GLOBAL_HOST

# Build the application
RUN npm run build

# Use the official Nginx image as the base image for the production stage
FROM nginx:alpine as production-stage

# Copy the built files from the previous stage
COPY --from=build-stage /app/dist /usr/share/nginx/html

# Copy the Nginx configuration file
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port 8081
EXPOSE 8081

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
